package cn.wolfcode.luowowo.website.web.controller;


import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Scenic;
import cn.wolfcode.luowowo.article.domain.StrategyCatalog;
import cn.wolfcode.luowowo.article.query.ScenicQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IScenicService;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.comment.domain.ScenicComment;
import cn.wolfcode.luowowo.comment.query.ScenicCommentQeury;
import cn.wolfcode.luowowo.comment.service.IScenicCommentService;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.website.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


/**
 * 景点控制器
 */
@Controller
@RequestMapping("/scenic")
public class ScenicController {

    @Reference
    private IDestinationService destinationService;

    @Reference
    private IStrategyCatalogService strategyCatalogService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IScenicService scenicService;

    @Reference
    private IScenicCommentService scenicCommentService;

    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") ScenicQuery qo){
        List<Destination> toasts = destinationService.getToasts(qo.getDestId());
        Destination dest = toasts.remove(toasts.size() - 1);
        model.addAttribute("toasts",toasts);
        model.addAttribute("dest",dest);

        model.addAttribute("catalogs",strategyCatalogService.getCatalogByDestId(qo.getDestId()));
        model.addAttribute("type","景点");//面包屑里的显示类型
        model.addAttribute("scenicTop5", scenicService.queryScenicTop5ByDestId(qo.getDestId()));
        model.addAttribute("hot",scenicService.queryHotTop10(qo.getDestId()));
//        model.addAttribute("page",scenicService.query(qo));

        return "destination/scenicList";
    }

    @RequestMapping("/detail")
    public String detail(Model model, ScenicCommentQeury qo){
        Scenic scenic = scenicService.getScenicWithRefScenics(new ObjectId(qo.getScenicId()));
        model.addAttribute("scenic", scenic);

        List<Destination> toasts = destinationService.getToasts(scenic.getDestId());
        Destination dest = toasts.remove(toasts.size() - 1);
        model.addAttribute("toasts",toasts);
        model.addAttribute("dest",dest);
        model.addAttribute("type","景点");

        List<StrategyCatalog> catalog = strategyCatalogService.getCatalogByDestId(scenic.getDestId());
        model.addAttribute("catalogs",catalog);

        return "destination/scenicDetail";
    }

    @RequestMapping("/commentAdd")
    public String commentAdd(Model model,ScenicComment scenicComment, @UserParam UserInfo userInfo){
        model.addAttribute("c",scenicCommentService.commentAdd(scenicComment,userInfo));
        return "destination/commentTpl";
    }

    @RequestMapping("/searchCommentPageTpl")
    public String searchCommentPageTpl(Model model,ScenicCommentQeury qo){
        model.addAttribute("page",scenicCommentService.query(qo));
        return "destination/commentPageTpl";
    }

    @RequestMapping("/searchScenicPage")
    public String searchScenicPage(Model model,ScenicQuery qo){
        model.addAttribute("page",scenicService.query(qo));
        return "destination/allScenicsTpl";
    }

    @RequestMapping("/refCommentAdd")
    public String refCommentAdd(Model model,ScenicComment scenicComment, @UserParam UserInfo userInfo){
        model.addAttribute("refc",scenicCommentService.refCommentAdd(scenicComment,userInfo));
        return "destination/refCommentTpl";
    }

}
